using System;
using dbvc.data;
using dbvc.Queries;

namespace dbvc.context.Project
{
    public static partial class Project
    {
        public static void Save(this db_project self)
        {
            GenericQuery<db_project>.Create(self, (o, i) => o.id = i);
        }
    }

    public static class Activity
    {
        public static void Save(this db_activity self)
        {
            GenericQuery<db_activity>.Create(self);
        }
    }

    public class CreateProject
    {
        private readonly db_activity activity;
        private readonly db_project project;
        private readonly db_user user;

        public CreateProject(db_user _principal, db_project _project)
        {
            user = _principal;
            project = _project;

            activity = new db_activity {action = "add project", datestamp = DateTime.Now, userstamp = user.name};
        }

        public db_project Execute()
        {
            project.Save();
            activity.Save();
            
            return project;
        }
    }
}